﻿using System;


namespace libemscontrol.act
{

    class SendMemData
    {
        public byte[] IEnable = new byte[4] { 0,0,0,0};
       private static SendMemData SendDataInstacne = null;
        object EnLock = new object();
        SendMemData()
        {

        }

        public void SetBit(int pos)
        {
            lock (EnLock)
            {
                int Grp = pos / 8;
                int Index = 7-pos % 8;
                IEnable[Grp] |= (byte)(0x1 << Index);
            }           
        }

       static object locker = new object();
        public static SendMemData GetInstance()
        {
            lock (locker)
            {
                if (SendDataInstacne == null)
                {
                    SendDataInstacne = new SendMemData();
                    return SendDataInstacne;
                }
            }

            return SendDataInstacne;
        }
        byte[] Buffer = new byte[] { 0,0,0,0};
        public byte[] GetBytes()
        {
            lock(EnLock)
            {
                for (int i = 0; i < 4; i++)
                {
                    Buffer[i] = IEnable[i];
                    IEnable[i] = 0;
                }
            }

            return Buffer;

        }
    }
}
